package com.owner.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.owner.biz.PremissionRoleBiz;
import com.owner.biz.UserBiz;
import com.owner.entity.PremissionRole;
import com.owner.entity.User;

@Controller
public class LoginController {

	@Autowired
	private UserBiz userBiz;
	@Autowired
	private PremissionRoleBiz premissionRoleBiz;
	@RequestMapping("/showlogin")
	public String login(){
		
	
		return "login";
	}

	
	
	
	@RequestMapping("Login")
	public String getByLogin(Model model, String name, String pwd,HttpSession session) {
		User user = userBiz.getByLogin(name, pwd);
		if (user != null) {
			System.out.println("登录成功");
			session.setAttribute("user", user);
//			if(user.getRole().getId()==1){
//				return  "ownerss";
//			}
//			else
				if(user.getRole().getId()==2){
					PremissionRole premissionRole1=premissionRoleBiz.checkBox(1);
					PremissionRole premissionRole2=premissionRoleBiz.checkBox(2);
					PremissionRole premissionRole3=premissionRoleBiz.checkBox(3);
					PremissionRole premissionRole4=premissionRoleBiz.checkBox(4);
					PremissionRole premissionRole5=premissionRoleBiz.checkBox(5);
					PremissionRole premissionRole6=premissionRoleBiz.checkBox(6);
					PremissionRole premissionRole7=premissionRoleBiz.checkBox(7);
					session.setAttribute("premissionRole1",premissionRole1);
					session.setAttribute("premissionRole2",premissionRole2);
					session.setAttribute("premissionRole3",premissionRole3);
					session.setAttribute("premissionRole4",premissionRole4);
					session.setAttribute("premissionRole5",premissionRole5);
					session.setAttribute("premissionRole6",premissionRole6);
					session.setAttribute("premissionRole7",premissionRole7);
				return "index";
			}else if(user.getRole().getId()==3){
				return "PPindex";
			}
			
		} else {
			System.out.println("登录失败!");
		}
		
		return "redirect:showlogin";
	}
}
